package com.banciyuan.bcywebview.biz.topic;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.base.activity.BaseActivity;
import com.banciyuan.bcywebview.base.helper.ActionbarHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by squall on 2015/8/14.
 */
public class TopicDetailListActivity extends BaseActivity {

    private ViewPager mViewPager;
    private TabLayout tabLayout;
    private List<Fragment> flist = new ArrayList<>();
    private String[] titles;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mymark_layout);
        getFragment();
        initArgs();
        initActionbar();
        initUi();
        initAction();
    }

    @Override
    protected void initArgs() {
        titles = getResources().getStringArray(R.array.tuijian_lists);
    }

    private void getFragment() {
        for (int i = 0; i < 5; i++) {
            TopicDetailListFragment topicDetailListFragment = new TopicDetailListFragment();
            flist.add(topicDetailListFragment);
        }
    }

    @Override
    protected void initUi() {
        mViewPager = (ViewPager) findViewById(R.id.mymark_viewpager);
        tabLayout = (TabLayout) findViewById(R.id.mymark_tablayout);
        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return flist.get(position);
            }

            @Override
            public int getCount() {
                return flist.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }
        });
        mViewPager.setOffscreenPageLimit(5);
        tabLayout.setupWithViewPager(mViewPager);
    }


    @Override
    protected void initActionbar() {
        View mActionBarView = findViewById(R.id.base_action_bar);
        ActionbarHelper mActionbarHelper = new ActionbarHelper(this, mActionBarView);
        mActionbarHelper.setTitle(getString(R.string.todayrecommend));
    }


    @Override
    protected void onSaveInstanceState(Bundle outState) {

    }
}
